package com.agiantii.ablog.mapper;

import com.agiantii.ablog.pojo.UserFollow;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserFollowMapper {
    
    @Select("SELECT * FROM user_follow WHERE follower_id = #{followerId} " +
            "AND following_id = #{followingId}")
    UserFollow findByFollowerAndFollowing(@Param("followerId") Long followerId, 
                                        @Param("followingId") Long followingId);
    
    @Insert("INSERT INTO user_follow(follower_id, following_id) " +
            "VALUES(#{followerId}, #{followingId})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(UserFollow userFollow);
    
    @Delete("DELETE FROM user_follow WHERE follower_id = #{followerId} " +
            "AND following_id = #{followingId}")
    int delete(@Param("followerId") Long followerId, 
              @Param("followingId") Long followingId);
    
    @Select("SELECT * FROM user_follow WHERE follower_id = #{followerId}")
    List<UserFollow> findByFollowerId(Long followerId);
    
    @Select("SELECT * FROM user_follow WHERE following_id = #{followingId}")
    List<UserFollow> findByFollowingId(Long followingId);
    
    @Select("SELECT COUNT(*) FROM user_follow WHERE follower_id = #{userId}")
    long countFollowing(Long userId);
    
    @Select("SELECT COUNT(*) FROM user_follow WHERE following_id = #{userId}")
    long countFollowers(Long userId);
} 